<template>
	<view class="body">
		<image src="../../static/img/pic-1.png" class="img"></image>
		<view class="loginbox">
			
			<view class="login">
				<view class="num"><input type="text" value="" placeholder="请输入手机号" v-model="mobile" maxlength="11"/></view>
				<view class="line">
					
				</view>
				<view class="pass">
					<input type="password" value="" placeholder="请输入验证码" v-model="code"/>
					<button @click="getcode" :disabled="disabled">{{codetip}}</button>
				</view>
			</view>
			
		</view>
		<!-- 协议 -->
		<view class="protocol">
			<label class="radio"><radio value="r1" checked="true" />
			我已阅读并同意<text>《用户使用协议》</text>和<text>《隐私政策》</text>
			</label>
		</view>
		<button class="loginbtn" @click="go">
			下一步
		</button>
		
	</view>
</template>

<script>
	import {sendcode,regByCode} from '../../api/user.js'
	export default{
		data(){
			return{
				mobile:'',
				code:'',
				codetip:'获取验证码',
				disabled:false,
				time:60,
				btnnum:0
			}
		},
		methods:{
			// 发送验证码
			async getcode(){
				if(this.mobile==''){
					uni.showToast({
						titlt:'手机号不能为空'
					})
				}else{
					const params={
					mobile:this.mobile
				}
				let res = await sendcode(params)
				this.gettimer()
				}
				
			},
			gettimer(){
					this.time=60
					this.timer()
			  
			  },
			// 倒计时
			timer(){
				if(this.time>0){
					this.disabled=true
					this.time--
					this.codetip=this.time+"秒"
					setTimeout(this.timer,1000)
				}else{
					this.time=0
					this.codetip="发送验证码"
					this.disabled=false
				}		
			},
			async go(){
				if(this.mobile==''){
					uni.showToast({
						title:'手机号不能为空'
					})
				}else if(this.pass==''){
					uni.showToast({
						title:'验证码不能为空'
					})
				}else{
				let res  = await regByCode({mobile:this.mobile,code:this.code})
				console.log(res)
				uni.navigateTo({
					url:'/pages/login/regpass?model='+this.mobile
				})
			}
			}
		}
	}
</script>
<style lang="less">
@import '@/static/style/reg.less';
</style>
